<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            height: 6000px;
        }
        button{
            position: fixed;
            left: 20px;
            bottom: 20px;
            display: none;
            width: 100px;
            height: 50px;
        }
    </style>
</head>
<body>
    <button id="tops">
        回到顶部
    </button>
    <script>

            var wtop,timer;
            window.onscroll=function(){
                wtop=window.scrollY
                wtop>=1000&&(tops.style.display="block")
                wtop<1000&&(tops.style.display="none")

            }
            
            tops.onclick=function(){
                clearInterval(timer)
                 timer=setInterval(function(){
                    wtop>0&&window.scrollTo({top:wtop-100})
                    wtop<=0&&clearInterval(timer)

                },50)
                
            }
              
            
        
    </script>
</body>
</html>